﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="H2.NET.Web.Workflow.Inbox" Codebehind="Inbox.aspx.cs" %>
<%@ Register src="../UserControls/Pager.ascx" tagname="Pager" tagprefix="uc1" %>
<%@ Register src="../UserControls/Toolbar.ascx" tagname="Toolbar" tagprefix="uc1" %>

<style type="text/css">
    .htable td a{ width: auto;display: inherit; }
    .htable tr th { border-top: 0;}
</style>
<script type="text/javascript">
    $(document).ready(function () {
        $(".countdown").each(function () {
            var id = $(this).attr("id");
            if (id != "") {
                onTimer("." + id.replace(".", "\\."), id);
            }
        });

        var style = $("#inboxStyle").val();
        if (style == "fixed") {
            $(".back span").text("自适应表格");
        } else {
            $(".back span").text("固定表格");
        }
    });
    // 该函数用于执行倒计时
    function onTimer(id, time) {
        // 将传进来的long型转换成秒
        var remainingTime = time;
        var hour = 0;
        var minute = 0;
        var second = 0;

        // 需要将其句柄赋予一个变量，方便清除该事件
        var stopCountDown = setInterval(countDown, 1000);

        function countDown() {
            if (remainingTime > 0) {
                // 如果倒计时大于0，则继续倒计时
                hour = Math.floor(remainingTime / 3600);
                minute = Math.floor(Math.floor(remainingTime % 3600) / 60);
                second = Math.floor(remainingTime % 60);
                var formatTime = numToDate(hour, minute, second);
                changeShowTime(id, formatTime);
                remainingTime--;

                /* 这里可用Ajax提交到服务器的 */

            } else {
                // 若倒计时为0，则清除事件
                clearInterval(stopCountDown);
                console.log(id.replace(".", "\."));
                $(id).html("Overdue");
            }
        }
    }

    // 将数字转换成时间格式，如： 09:30:45
    function numToDate(hour, minute, second) {
        var tohour = hour < 10 ? ("0" + hour) : hour;
        var tominute = minute < 10 ? ("0" + minute) : minute;
        var tosecond = second < 10 ? ("0" + second) : second;
        return tohour + ":" + tominute + ":" + tosecond;
    }

    // 该函数用于显示倒计时
    function changeShowTime(id, time) {
        /* 该函数内编写显示倒计时的语句 */
        $(id).html(time);
    }


    function NewStoreApplicationBatchApprove() {
        var selected = [];
        var $checkboxLi = $(":checkbox[name='ids']:checked", navTab.getCurrentPanel());

        if ($checkboxLi.size() == 0) {
            alertMsg.warn("至少选择一条数据");
            return false;
        }

        var pass = false;
        var ps = false;
        var pName = "";
        var sName = "";
        var url = "";
        $checkboxLi.each(function () {
            var processName = $(this).parents("tr").attr("process");
            var stepName = $(this).parents("tr").attr("step");
            if (!pName) {
                pName = processName;
            }
            if (!sName) {
                sName = stepName;
            }
            if (pName != processName || sName != stepName) {
                ps = true;
            }
            switch (processName) {
                case "New Store Application":
                    pass = stepName == "Assign AuthID";
                    if (pass) {
                        url = "/Pages/smd/StoreBatchApprove.aspx";
                    }
                    break;
                case "Store Deposit Receive":
                    //pass = stepName == "Finance Confirm" || stepName == "Delivery Device";
                    pass = stepName == "Finance Confirm";
                    if (pass) {
                        url = sName == "Finance Confirm" ? "/Pages/smd/FinanceBatchConfirm.aspx" : "/Pages/smd/DeliveryBatchDevice.aspx";
                    }
                    break;
            }
            if (pass) {
                if (processName == "New Store Application") {
                    selected.push($(this).attr("value"));
                } else {
                    selected.push($(this).attr("incident"));
                }
            }
            else {
                ps = true;
            }
        });

        // 验证是否支持批量处理
        if (ps) {
            alertMsg.warn("请选择相同的步骤进行批量处理，且目前只支持部分节点进行批量处理！");
            return false;
        }
        var taskid = $checkboxLi.eq(0).parents("tr").attr("taskid");

        if ($checkboxLi.eq(0).parents("tr").attr("process") == "New Store Application") {
            window.open(url + "?taskid=" + taskid + "&ids=" + selected.join(","));
        } else {
            window.open(url + "?taskid=" + taskid + "&incidents=" + selected.join(","));
        }

        return false;
    }

    function AssignConfer() {
        var selected = [];
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());
        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                selected.push($(this).attr("value"));
            }
        });
        $.pdialog.open("Workflow/AssignConfer.aspx" + "?ids=" + selected.join(","), "AssignConfer", "<%=clsCmm.getTextValue("frm_inbox_txt_assign_confer")%>", { width: 550, height: 260, mask: true });
        return false;
    }
    function TaskBack(url, rel, title) {
        $.pdialog.open(url, rel, '<%=clsCmm.getTextValue("frm_inbox_txt_take_back")%>', { width: 900, height: 500, mask: true });
        return false;
    }
    function TaskCancel(url, rel, title) {
        $.pdialog.open(url, rel, '<%=clsCmm.getTextValue("frm_inbox_btnCancel")%>', { width: 900, height: 500, mask: true });
        return false;
    }
    function PersonalInfo(url, rel, title) {
        $.pdialog.open(url, rel, '<%=clsCmm.getTextValue("frm_inbox_txt_persoanl_info")%>', { width: 600, height: 400, mask: true });
        return false;
    }
    function BatchApprove(url, rel, title) {
        $.pdialog.open(url, rel, '<%=clsCmm.getTextValue("frm_inbox_txt_BatchApprove")%>', { width: 900, height: 500, mask: true });
        return false;
    }

    function initOrderDir() {
        var orderDir = $("[name='orderDir']").val();
        if (orderDir != "") {
            if (orderDir == "asc")
                $("[name='orderDir']").val("desc");
            else
                $("[name='orderDir']").val("asc");
        }
    }

    function tranStyle() {
        var style = $("#inboxStyle").val();
        if (style == "fixed") {
            $("#inboxStyle").val("adjustable");
            $(".back span").text("自适应表格");
        } else {
            $("#inboxStyle").val("fixed");
            $(".back span").text("固定表格");
        }
        $('#pagerForm', navTab.getCurrentPanel()).submit();
    }
</script>

<div class="pageHeader">
    <div class="searchBar" id="todolist_searchBar">
    <form id="pagerForm" onsubmit="return navTabSearch(this);" action = "workflow/inbox.aspx" method="post" runat="server">
        <asp:hiddenfield id="hf_type" runat="server"></asp:hiddenfield>
        <input type="hidden" name="pageNum" value="<%= PageNumber %>" />
        <input type="hidden" name="numPerPage" value="<%= PageSize %>" />
	    <input type="hidden" name="orderField" value="<%= OrderField %>" />
        <input type="hidden" name="orderDir" value="<%= OrderDir %>" />
        <input type="hidden" id="inboxStyle" runat="server" />
        <table class="searchContent">
            <tr>
                <td>
                    <%= clsCmm.getTextValue("frm_inbox_txtProcess")%>
                    <asp:dropdownlist id="drpProcess" runat="server" onchange="$('#pagerForm', navTab.getCurrentPanel()).submit()"></asp:dropdownlist>
                
                    <%=clsCmm.getTextValue("frm_initiate_txtStep")%>
                    <asp:dropdownlist id="drpStep" runat="server" onchange="$('#pagerForm', navTab.getCurrentPanel()).submit()"></asp:dropdownlist>
                
                    <%= clsCmm.getTextValue("frm_inbox_txtIncidentFrom")%>
                    <input type="text" runat="server" id="txtIncidentFrom" size="8" /> 至
                    <input type="text" runat="server" id="txtIncidentTo" size="8" />
                
                    <%=clsCmm.getTextValue("frm_inbox_txtSummary") %>
                    <asp:TextBox ID="tb_Summary" runat="server" Width="194px"></asp:TextBox>
                </td>
            </tr>
        </table>
        <div class="subBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit" onclick="initOrderDir()">
                                <%=clsCmm.getTextValue("frm_inbox_btnSearch")%></button></div>
                    </div>
                </li>
            </ul>
        </div>
        
        <input type="hidden" id="tranStyle" runat="server" />
        </form>
    </div>
</div>

<div class="pageContent">
    <div class="panelBar">
        <ul class="toolBar">
           <uc1:Toolbar ID="Toolbar1" runat="server" />
        </ul>
        <ul class="toolBar" style="float:right;padding-left:3px">
            <li style="margin-top: -2px;"><a class="back" onclick="tranStyle()"><span>切换样式</span></a></li>
        </ul>
    </div>
    
        <%if(Style == "fixed"){ %>
        <table class="table" width="1500" layouth="137">
        <thead>
            <tr>
                <th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
                <th width="40" align="center">
                    <%=clsCmm.getTextValue("frm_inbox_gv_monitor")%>
                </th>
                <th width="40" align="center">
                    <%=clsCmm.getTextValue("frm_inbox_gv_status")%>
                </th>
                <th width="240" orderField="processname3" class="<%= OrderField == "processname3" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_process_name")%>
                </th>
                <th width="150" orderField="steplabel" class="<%= OrderField == "steplabel" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_step_name")%>
                </th>
                <th>
                    <%=clsCmm.getTextValue("frm_inbox_gv_summary")%>
                </th>
                <th width="80" orderField="Priority" class="<%= OrderField == "Priority" ? OrderDir : ""%>">Priority</th>
                <th width="110" orderField="urgentduetime" class="<%= OrderField == "urgentduetime" ? OrderDir : ""%>">Time Remaining</th>
                <th width="140" orderField="starttime" class="<%= OrderField == "starttime" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_start_time")%>
                </th>
                <th width="120">
                    <%=clsCmm.getTextValue("frm_inbox_gv_applicator")%>
                </th>
                <th width="120">
                    <%=clsCmm.getTextValue("frm_inbox_gv_owner")%>
                </th>
                <th width="50">
                    <%=clsCmm.getTextValue("frm_inbox_gv_incident_no")%>
                </th>
            </tr>
        </thead>
        <%}else{ %>
        <table class="htable" style="width:100%" layouth="115">
        <thead>
            <tr>
                <th width="20px"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
                <th width="40px" align="center">
                    <%=clsCmm.getTextValue("frm_inbox_gv_monitor")%>
                </th>
                <th width="40px" align="center">
                    <%=clsCmm.getTextValue("frm_inbox_gv_status")%>
                </th>
                <th width="8%" orderField="processname3" class="<%= OrderField == "processname3" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_process_name")%>
                </th>
                <th width="12%" orderField="steplabel" class="<%= OrderField == "steplabel" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_step_name")%>
                </th>
                <th width="24%">
                    <%=clsCmm.getTextValue("frm_inbox_gv_summary")%>
                </th>
                <th width="8%" orderField="Priority" class="<%= OrderField == "Priority" ? OrderDir : ""%>">Priority</th>
                <th width="8%" orderField="urgentduetime" class="<%= OrderField == "urgentduetime" ? OrderDir : ""%>">Time Remaining</th>
                <th width="8%" orderField="starttime" class="<%= OrderField == "starttime" ? OrderDir : ""%>">
                    <%=clsCmm.getTextValue("frm_inbox_gv_start_time")%>
                </th>
                <th width="8%">
                    <%=clsCmm.getTextValue("frm_inbox_gv_applicator")%>
                </th>
                <th width="8%">
                    <%=clsCmm.getTextValue("frm_inbox_gv_owner")%>
                </th>
                <th width="6%">
                    <%=clsCmm.getTextValue("frm_inbox_gv_incident_no")%>
                </th>
            </tr>
        </thead>
        <%} %>
        <tbody>
            <asp:repeater id="gvInbox" runat="server">
                <ItemTemplate>
                    <tr process='<%#Eval("processname3").ToString().Trim()%>' step='<%#Eval("steplabel").ToString().Trim()%>' taskid='<%# Eval("taskid") %>'>
                        <td><input name="ids" value="<%# Eval("taskid") %>" incident='<%#Eval("incident")%>' processname="<%# Eval("processname3")%>" type="checkbox"></td>
                        <td><a onclick="return openDialog('<%# Eval("processname3")%>', 'workflow/monitor.aspx?TaskID=<%# Eval("taskid") %>', 1000, 600)" target="_blank"><img alt="<%=clsCmm.getTextValue("frm_inbox_img_alt")%>" border="0" src="Resource/Images/<%# Eval("img_monitor") %>" width="16" height="16"></a></td>
                        <td><img alt="" border="0" src="Resource/Images/<%# Eval("img_status") %>" width="16" height="16"></td>
                        <td><a onclick="<%#Eval("openform")%>;$(this).parents('tr').hide();" target="_blank"><%# GetCache(Eval("processname3").ToString())%></a></td>
                        <td><%# Eval("steplabel").ToString() == "Manager Approve" ? (Eval("summary").ToString().Substring(0, 2) == "全国" ? "全国合同信息确认" : GetCache(Eval("steplabel").ToString())) : GetCache(Eval("steplabel").ToString())%></td>
                        <td title='<%# Eval("summary").ToString()%>'><a onclick="<%#Eval("openform")%>;$(this).parents('tr').hide();" target="_blank"><%# Eval("summary").ToString()%></a></td>
                        <td><div class="C<%# Eval("Priority")%>"><%# Eval("Priority")%> </div></td>
                        <td><div class="countdown <%# Eval("urgentduetime")%>" id="<%# Eval("urgentduetime")%>" ></div></td>
                        <td><%# Eval("starttime","{0:yyyy-MM-dd HH:mm}")%></td>
                        <td><%# Eval("initiator_name")%></td>
                        <td><%# Eval("taskuser_name")%></td>
                        <td><%#Eval("incident")%></td>
                    </tr> 
                </ItemTemplate>
                
            </asp:repeater>
        </tbody>
    </table>
</div>
<uc1:Pager ID="Pager1" runat="server" />